package com.cxcy.swustlearner.controller;

import com.cxcy.swustlearner.pojo.Major;
import com.cxcy.swustlearner.pojo.StaticUser;
import com.cxcy.swustlearner.service.MajorService;
import common.ConstStatus;
import common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/major")
public class MajorController {
    @Autowired
    private MajorService majorService;
    @GetMapping()
    public Result getAllMajor() {
        if (StaticUser.permission>=2){
            return Result.success(majorService.getMajors());
        }
            return Result.fail(ConstStatus.PERMISSION_DISABLED);
    }
    @PostMapping()
    public Result addMajor(@RequestBody Major major) {
        if (StaticUser.permission>=3){
            majorService.addMajor(major);
            return Result.success("添加成功");
        }
            return Result.fail(ConstStatus.PERMISSION_DISABLED);
    }
}